/*
 * Copyright (c) 2015 [1076559197@qq.com | tchen0707@gmail.com]
 *
 * Licensed under the Apache License, Version 2.0 (the "License”);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.framemodule.widgets.loading;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.framemodule.R;
import com.framemodule.utils.CommonUtils;

public class VaryViewHelperController {

    private IVaryViewHelper helper;

    public VaryViewHelperController(View view) {
        this(new VaryViewHelper(view));
    }

    public VaryViewHelperController(IVaryViewHelper helper) {
        super();
        this.helper = helper;
    }

    public void showLoading(String msg) {
        View layout = helper.inflate(R.layout.loading);
        if (!CommonUtils.isEmpty(msg)) {
            TextView textView = (TextView) layout.findViewById(R.id.loading_msg);
            textView.setText(msg);
        }
        helper.showLayout(layout);
    }

    public void restore() {
        helper.restoreView();
    }


    /**
     * 网络无法连接
     *
     * @param onClickListener
     */
    public void showNewNetworkError(View.OnClickListener onClickListener) {
        View layout = helper.inflate(R.layout.layout_net_question);
        layout.findViewById(R.id.tv_hint_info).setVisibility(View.GONE);

        if (null != onClickListener) {
            layout.findViewById(R.id.iv_fragment_refresh).setOnClickListener(onClickListener);
        }

        helper.showLayout(layout);
    }

    /**
     * 服务器开小差
     *
     * @param onClickListener
     */
    public void showNewError(View.OnClickListener onClickListener) {
        View layout = helper.inflate(R.layout.layout_net_question);
        layout.findViewById(R.id.tv_hint_info).setVisibility(View.VISIBLE);
        ((ImageView) layout.findViewById(R.id.iv_fragment_server_lose)).setImageResource(R.mipmap.server_logo);

        if (null != onClickListener) {
            layout.findViewById(R.id.iv_fragment_refresh).setOnClickListener(onClickListener);
        }

        helper.showLayout(layout);
    }

    /**
     * 空
     */
    public void showNewEmpty() {
        View layout = helper.inflate(R.layout.layout_net_question);
        layout.findViewById(R.id.ll_fragment_server_lose).setVisibility(View.GONE);
        layout.findViewById(R.id.iv_fragment_no_content).setVisibility(View.VISIBLE);
        helper.showLayout(layout);
    }
}
